 <template>
  <div class="index-box" ref="index">
    <el-row :gutter="10">
      <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
        <div class="moneyTotal" ref="moneyTotal" v-loading="topLoading">
            <div class="item">
              <div class="money">{{topData.promotingTransactionsNum}}</div>
              <div class="text">推广交易总人数(人)</div>
            </div>
            <div class="item">
              <div class="money">¥{{topData.transactionIncomeAmount}}</div>
              <div class="text">交易收益总金额(元)</div>
            </div>
            <div class="item">
              <div class="money">￥{{topData.totalWithdrawn}}</div>
              <div class="text">已提现总额(元)</div>
            </div>
            <div class="item">
              <div class="money">￥{{topData.withdrawableCashAmount}}</div>
              <div class="text">可提现总额(元)</div>
            </div>

        </div>
        <div class="search" ref="search">
          <el-form :inline="true" :model="searchForm" size="small" ref="searchForm" @submit.native.prevent class="demo-form-inline" id="searchBox">
            <el-form-item prop="telephone">
                <el-input v-model="searchForm.telephone" clearable placeholder="用户手机号"></el-input>
            </el-form-item>
            <el-form-item prop="name">
                <el-input v-model="searchForm.name" clearable placeholder="用户姓名"></el-input>
            </el-form-item>
             <el-form-item prop="levelId">
              <el-radio-group v-model="searchForm.levelId" size="small" @change="handleSearch" style="margin-right: 10px;">
                <el-radio-button label="">全部</el-radio-button>
                <el-radio-button :label="item.levelId" v-for="item in levelList">{{item.name}}</el-radio-button>
              </el-radio-group>
             </el-form-item>

            <el-form-item class="clearfix">
              <el-button type="primary" @click="handleSearch()" icon="el-icon-search">搜索</el-button>
              <el-button icon="el-icon-refresh" size="small" @click="resetSearch">重置</el-button>
              <el-button
                type="warning"
                icon="el-icon-download"
                size="small"
                :loading="btnLoading"
                @click="handleExport"
              >导出</el-button>
            </el-form-item>
            <div class="actionBtnRight" style="margin-left:auto">
                <MyRefresh></MyRefresh>
                <MyTableColumnSet :tableColumn.sync="tableColumn" :hideTableColumn.sync="hideTableColumn" :tableColumnType.sync="tableColumnType"></MyTableColumnSet>
            </div>
          </el-form>
        </div>
        <div class="table" ref="table">
          <el-table :data="dataList" style="width: 100%" row-key="id" border :height="tableHeight" v-loading="loading" stripe>
            <el-table-column prop="userface" label="推广人头像" v-if="!hideTableColumn.includes('img')" align="center">
              <template #default="scope">
                 <el-image :src="scope.row.userface" fit="fill" v-image-preview="scope.row.userface" class="img"></el-image>
              </template>
            </el-table-column>
            <el-table-column prop="telephone" label="推广人手机号" v-if="!hideTableColumn.includes('phone')" align="center"></el-table-column>
            <el-table-column prop="name" label="推广人姓名" v-if="!hideTableColumn.includes('name')" align="center"></el-table-column>
            <el-table-column prop="levelName" label="用户等级" v-if="!hideTableColumn.includes('levelName')" align="center"></el-table-column>
            <el-table-column prop="transactionsNumber" label="交易总人数" v-if="!hideTableColumn.includes('total')" align="center"></el-table-column>
            <el-table-column prop="transactionIncomeAmount" label="交易收益总计金额" v-if="!hideTableColumn.includes('totalMoney')" align="center"></el-table-column>
            <el-table-column prop="totalWithdrawn" label="已提现合计(元)" v-if="!hideTableColumn.includes('yiWithdraw')" align="center"></el-table-column>
            <el-table-column prop="withdrawableCashAmount" label="可提现合计(元)" v-if="!hideTableColumn.includes('keWithdraw')" align="center"></el-table-column>
            <el-table-column prop="name" label="推广交易明细" v-if="!hideTableColumn.includes('PromotionTrade')" align="center">
              <template #default="scope">
                  <el-button
                    size="medium"
                    type="text"
                    icon="el-icon-s-claim"
                    @click="handleDetail(scope.row)"
                  >详情</el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div class="page" ref="page">
         <MyPagination
            :total="total"
            :page.sync="searchForm.pageNum"
            :limit.sync="searchForm.pageSize"
            @pagination="dataInfo"
          />
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
  import common from '@/api/api';
  import {
    getTransactionIncomeQuantity,promotionTransactionItemList,promotionTransactionItemQuantity,transactionIncomeExport,transactionIncomeList,getAllMemberLevel
  } from '@/api/getData'
  import option from '../../common/option.js';

  export default {
    data() {
      return {
        loading: false,
        btnLoading:false,
        searchForm: {
           name:"",
           telephone:'',
           levelId:'',
           pageNum: 1,
           pageSize: 20,
        },
        tableColumn:[{/*自定义表格列*/
            name:'序号',
            value:'number'
        },{
            name:'推广人头像',
            value:'img'
        },{
            name:'推广人手机号',
            value:'phone'
        },{
            name:'推广人姓名',
            value:'name'
        },{
            name:'交易总人数',
            value:'total'
        },{
            name:'交易收益总计金额',
            value:'totalMoney'
        },{
            name:'已提现合计(元)',
            value:'yiWithdraw'
        },{
            name:'可提现合计(元)',
            value:'keWithdraw'
        },{
            name:'推广交易明细',
            value:'PromotionTrade'
        }],
        hideTableColumn:[],/*自定义表格列需要隐藏的*/
        tableColumnType:'staffManagement',/*自定义表格列类型传参*/
        tableHeight:0,//table 高度
        topData:{},
        dataList:[],
        total: 0,
        levelList:[],
        topLoading:true
      }
    },
    created() {
      getAllMemberLevel().then(res=>{
        this.levelList = res.data;
      })
    },
    mounted() {
      this.dataInfo();
      this.topDataInfo();
      this.$nextTick(() => {
          this.tableHeight = this.$refs.index.offsetHeight - this.$refs.moneyTotal.offsetHeight - this.$refs.search.offsetHeight  - this.$refs.page.offsetHeight - 55;
      })
    },
    methods: {
      handleDetail(row){
         this.$router.push({path:'/statistics/promotionDetail',query:{phone:row.telephone,customerId:row.customerId}});
      },
      topDataInfo(){
        this.topLoading = true;
         getTransactionIncomeQuantity(this.searchForm).then((res)=>{
           this.topData = res.data;
           this.topLoading = false;
         })
       },
       /** 导出按钮操作 */
       handleExport() {
         this.$modal.confirm('是否确认导出搜索数据项？').then(() => {
           this.btnLoading = true;
           return transactionIncomeExport(this.searchForm);
         }).then(response => {
           this.$download.name(response.msg);
           this.btnLoading = false;
         }).catch(() => {});
      },
      resetSearch(){
          this.searchForm.levelId = '';
          this.resetForm('searchForm');
          this.dataInfo();
          this.topDataInfo();
      },
      handleSearch(){
          this.searchForm.pageNum = 1;
          this.dataInfo();
          this.topDataInfo();
      },
      async dataInfo() {
        try {
          this.loading = true;
          const result = await transactionIncomeList(this.searchForm);
          if (result.code == 200) {
            this.total = result.total;
            this.dataList = result.rows;
          } else {
            this.$message.error(result.msg);
          }
          this.loading = false;
        } catch (err) {
          this.loading = false;
          console.log(err)
        }
      },

    }
  }
</script>

<style scoped lang="scss">

  .el-table .el-dropdown-link{
      cursor: pointer;
      color: #61997A;
      margin-left: 5px;
  }
    .leftDialog{
      height:540px;
      overflow-y: auto;
    }
    .activeVerticalBox .activeItem{
      color:#61997A;
      cursor: pointer;
      margin: 0px;
      text-align: center;
      height:20px;
      line-height: 20px;
    }
    .activeVerticalBox .el-dropdown{
      display: flex;
      justify-content: center;
      color:#61997A;
      cursor: pointer;
    }
    .activeCheckedBox{
      border-top: 1px solid #ddd;
      padding:10px;
      height:52px;
      .el-tag{
        margin-right:10px;
      }
    }
    .rateBox /deep/ .el-rate__icon{
      margin-right: 0px;
    }
    .rateBox>p{
      margin: 0px;
    }
    .rateBox>p> /deep/ .el-rate{
      height:25px;
      line-height:25px;
      display:flex;
    }
    .rateBox>p> /deep/ .el-rate .el-rate__item{
      display:flex;
      align-items: center;
    }
    .rateBox .rateText{
      width:60px;
    }
    .rateBox .content{
      display: flex;
    }
    .rateBox .el-tooltip{
      width: 100px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      display: inline-block;
    }
</style>
